package ru.marketsoft.reminder.tools;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * User: dimka3210
 * Date: 28.02.13
 * Time: 20:42
 */
public class Utils {

    private static Calendar cal = Calendar.getInstance();
    private static int offsetHours = (cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60));
    private static String checked = "►";

    public static Dimension getUseFul(JFrame jFrame) {
        return new Dimension(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height - Toolkit.getDefaultToolkit().getScreenInsets(jFrame.getGraphicsConfiguration()).bottom);
    }

    public static int getHours() {
        //int hour = (offsetHours == 3) ? (cal.get(Calendar.HOUR_OF_DAY) + 1) : cal.get(Calendar.HOUR_OF_DAY);
        String timeStamp = new SimpleDateFormat("HH").format(Calendar.getInstance().getTime());
        int hour = Integer.parseInt(timeStamp);
        return hour;
    }

    public static int getMinutes() {
        String timeStamp = new SimpleDateFormat("mm").format(Calendar.getInstance().getTime());
        int minutes = Integer.parseInt(timeStamp);
        return minutes;
    }

    public static int getReminderHours(int what /* 1 hour or 2 minutes */) throws IOException {
        /*BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("ru/marketsoft/reminder/time.ini")));
        String line;
        if ((line = bufferedReader.readLine()) == null) {
            return 0;
        }
        String[] time = line.split(":");*/

        if (what == 1) {
            /*return Integer.parseInt(time[0]);*/
            return Integer.parseInt(Settings.getInstance().getProperty("time.hours"));
        } else if (what == 2) {
            /*return Integer.parseInt(time[1]);*/
            return Integer.parseInt(Settings.getInstance().getProperty("time.minutes"));
        } else {
            return 0;
        }
    }

    public static String beautifulFormatDate(int hour, int minutes) {
        String result = "";
        if (hour < 10 || hour == 0) {
            result += "0" + hour;
        } else {
            result += hour;
        }

        result += ":";

        if (minutes < 10 || minutes == 0) {
            result += "0" + minutes;
        } else {
            result += minutes;
        }

        return result;
    }

    public static String getChecked() {
        return checked;
    }

    public static Image getIcon(){
        return Toolkit.getDefaultToolkit().createImage("ru/marketsoft/reminder/icon.png");
    }
}
